import xlrd
import xlutils.copy

newwb = xlrd.open_workbook("/home/yangming/hook.xls", formatting_info=True)  # formatting_info 带格式导入
outwb = xlutils.copy.copy(newwb)  # 建立一个副本来用xlwt来写


# 修改值


def setOutCell(outSheet, col, row, value):
    def _getOutCell(outSheet, colIndex, rowIndex):
        row = outSheet._Worksheet__rows.get(rowIndex)
        if not row: return None
        cell = row._Row__cells.get(colIndex)
        return cell

    previousCell = _getOutCell(outSheet, col, row)
    styleCell = _getOutCell(outSheet, 6, 1)
    outSheet.write(row, col, value)
    if previousCell:
        newCell = _getOutCell(outSheet, col, row)
        if newCell:
            newCell.xf_idx = styleCell.xf_idx


outSheet = outwb.get_sheet(0)
setOutCell(outSheet, 3, 4, 'CN')
outwb.save('/home/yangming/hook.xls')
